﻿<?php
!defined('IN_FENGTOPsso') && exit('Access Denied');

class RegisterActive extends Base{
	private $key;
	private $mail;
	private $userName;
	
	function __construct() {
		parent::__construct();
		$this->key  = daddslashes($_GET['key']);
		$this->mail = daddslashes($_GET['mail']);
	}
	
	public function registerActiveRun(){
		if($this->chickIn()){
			if($this->setEmailStatus()){
				//if($this->deleteEmailStatus()){
					echo '激活成功！';
				//}
			}else {
				echo '设置状态失败，请与管理员联系。';
			}
		}else {
			echo '已经激活，不能重复激活。';
		}
	}

	private function chickIn(){
		$getMailAttestation = 'select * from `'.$GLOBALS['_FENGTOPsso']['db']['1']['tablepre'].'mail_attestation` 
		                        where `attestationkey` = \''.$this->key.'\' 
		                          and `email` = \''.$this->mail.'\'';
		$result = $this->mysqldb->GetOne($getMailAttestation);
//echo $getMailAttestation;print_r($result);
		if($result != 0){
			$this->userName = $result['username'];
			return 1;
		}
		return 0;
	}
	
	private function setEmailStatus(){
		$setEmailStatusSQL = "UPDATE `{$GLOBALS['_FENGTOPsso']['db']['1']['tablepre']}user_".substr(md5($this->userName), 0, 2)."` 
		                         SET `emailstatus` = '1' WHERE `username` = '$this->userName'";
//echo $setEmailStatusSQL;
		$result = $this->mysqldb->Query($setEmailStatusSQL);
		return $result;
	}
	
	private function deleteEmailStatus(){
		$deleteEmailStatusSQL = "DELETE FROM `{$GLOBALS['_FENGTOPsso']['db']['1']['tablepre']}mail_attestation`
		                               WHERE `email` = '{$this->mail}'";
		$result = $this->mysqldb->Query($deleteEmailStatusSQL);
		return $result;
	}
}
?>